package everydayGrade.t4;

import java.sql.Connection;
import java.util.Arrays;

/**
 * @Author: Siantar
 * @Date: 2024-07-22-8:44
 * @Description: 1.0
 */
public class T2101 {
    public int maximumDetonation(int[][] bombs) {
        int len = bombs.length, max = 0;
        for (int i = 0; i < len; i++) {
            boolean[] vis = new boolean[bombs.length];
            Arrays.fill(vis, false);
            max = Math.max(max, dfs(bombs, vis, i));
        }
        return max;
    }

    public int dfs(int[][] bombs, boolean[] vis, int x) {
        vis[x] = true;
        int[] a = bombs[x];
        int count = 1;
        for (int i = 0; i < bombs.length; i++) {
            if (isIn(a, bombs[i]) && !vis[i]) {
                count += dfs(bombs, vis, i);
            }
        }
        return count;
    }

    public boolean isIn(int[] a, int[] b) {
        double distance = Math.sqrt(Math.pow(a[0] - b[0], 2) + Math.pow(a[1] - b[1], 2));
        return distance <= a[2];
    }
}
